import { CallHandler, ExecutionContext, Injectable, NestInterceptor } from '@nestjs/common';
import { Observable, map } from 'rxjs';

@Injectable()
export class ResponseInterceptor implements NestInterceptor {
  intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
    //设置响应返回的数据格式
    return next.handle().pipe(map((data)=>{
      return {
        error:0,
        msg:data,
        status:context.switchToHttp().getResponse().statusCode,
        time: new Date().getTime()
      }
    }));
  }
}
